;;; guix-config --- additional software for a custom configuration of gnu-guix
;;; Copyright © 2020 Kolya <kolya.daemon@vfemail.net>
;;;
;;; This file is part of guix-config
;;;
;;; guix-config is free software; you can redistribute it and/or modify it
;;; under the terms of the GNU General Public License as published by
;;; the Free Software Foundation; either version 3 of the License, or (at
;;; your option) any later version.
;;;
;;; guix-config is distributed in the hope that it will be useful, but
;;; WITHOUT ANY WARRANTY; without even the implied warranty of
;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;;; GNU General Public License for more details.
;;;
;;; You should have received a copy of the GNU General Public License
;;; along with GNU Guix.  If not, see <http://www.gnu.org/licenses/>.

(define-module (kolyad utils)
  #:use-module (srfi srfi-1)
  #:export (list-params
            delete-all
            replace
            replace-all
            delete-and-replace-all))

(define (with-argument arg)
  (lambda (f) (f arg)))

(define (list-params exp parameters from)
  (if (null? parameters)
      from
      (exp (car parameters) (list-params exp (cdr parameters) from))))

(define (delete-all matches from)
  (filter (lambda (element)
            (not (member element matches)))
    from))

(define (replace pair from)
  (cond ((list? from)
         (map (lambda (lst) (replace pair lst))
          from))
        (else
          (if (equal? (car pair) from)
            (cadr pair)
            from))))

(define (replace-all parameters from)
  (list-params replace parameters from))

(define (delete-and-replace-all delete-lst replace-lst from)
  (replace-all replace-lst (delete-all delete-lst from)))

;;; vim: set expandtab tabstop=2 shiftwidth=2
;;; end of file util.scm
